package com.fang.dubbo.mock.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author fanglingxiao
 * @createDateTime 2022/1/2 12:07 下午
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class FangResponse<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private static final Integer SUCC_CODE = 200;
    private static final Integer ERROR_CODE = 500;
    private Boolean success;
    private T data;
    private Integer code;
    private String msg = "操作成功";

    public static <T> FangResponse<T> fail(String msg) {
        FangResponse<T> response = new FangResponse();
        response.setSuccess(Boolean.FALSE);
        response.setCode(ERROR_CODE);
        response.setMsg(msg);
        return response;
    }

    public static <T> FangResponse<T> fail(Integer code, String msg) {
        FangResponse<T> response = new FangResponse();
        response.setSuccess(Boolean.FALSE);
        response.setCode(code);
        response.setMsg(msg);
        return response;
    }

    public static <T> FangResponse<T> fail(FangResponse<T> response, Integer code, String msg) {
        response.setSuccess(Boolean.FALSE);
        response.setCode(code);
        response.setMsg(msg);
        return response;
    }

    public static <T> FangResponse<T> succ(T data, String msg) {
        FangResponse<T> response = new FangResponse();
        response.setSuccess(Boolean.TRUE);
        response.setCode(SUCC_CODE);
        response.setData(data);
        response.setMsg(msg);
        return response;
    }

    public static <T> FangResponse<T> succ(T data) {
        FangResponse<T> response = new FangResponse();
        response.setSuccess(Boolean.TRUE);
        response.setCode(SUCC_CODE);
        response.setData(data);
        return response;
    }

    public static <T> FangResponse<T> succ() {
        FangResponse<T> response = new FangResponse();
        response.setSuccess(Boolean.TRUE);
        response.setCode(SUCC_CODE);
        return response;
    }
}